import { Component, OnInit } from '@angular/core';

import { NavController } from "@ionic/angular";

import { ActivatedRoute } from "@angular/router";

import { CommonService } from "../services/common.service";

@Component({
  selector: 'app-detail',
  templateUrl: './detail.page.html',
  styleUrls: ['./detail.page.scss'],
})
export class DetailPage implements OnInit {

  public detailInfo = {};
  public hasData: boolean = false;
  public infoText: string = '拼命加载中..';

  constructor(public navCtr: NavController,
    public activatedRoute: ActivatedRoute,
    public commonService: CommonService) {
    console.log(this.navCtr);
    this.activatedRoute.queryParams.subscribe((data) => {
      console.log(data.aid);
      this.getDetail(data.aid);
    });
  }

  ngOnInit() {
  }

  getDetail(aid) {
    let detail_url = 'http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid=' + aid;
    this.commonService.ajaxGet(detail_url)
      .then((data: any) => {
        this.detailInfo = data.result[0];
        this.hasData = true;
        console.log(data);
      })
      .catch((error) => {
        console.log(error);
      });
  }
}
